<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <script type="text/javascript" charset="utf-8" th:src="@{/ueditor/ueditor.config.js}"></script>
    <script type="text/javascript" charset="utf-8" th:src="@{/ueditor/ueditor.all.js}"> </script>
    <script type="text/javascript" charset="utf-8" th:src="@{/ueditor/lang/zh-cn/zh-cn.js}"> </script>
    <title></title>
</head>
<body>
<article class="page-container saveProductChannelFee">
    <form action="" method="post" class="form form-horizontal" id="tradeForm">
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>产品名称：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="name" name="name"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>规格简介：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="unit" name="unit"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>成员身份升级：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="custVipType" id="custVipType">
                        <option value="">-请选择-</option>
                        <option value="10">勇猛创业者</option>
                        <option value="20">股东合伙人</option>
                        <option value="30">区县市代理</option>
                    </select>
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>产品显示位置：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <select name="category" id="category">
                        <option value="">-请选择-</option>
                        <option value="1">首页区产品</option>
                        <option value="2">加盟区产品</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>供货商：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="vendor" name="vendor"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>单价：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="price" name="price"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>下单得酒票数：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="cloudTicket" name="cloudTicket"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>下单得酒钻数：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="cloudPoint" name="cloudPoint"
                           onblur="replaceSpace(this.value,this.id)">
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
        </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>产品排序规则：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <input type="text" class="input-text" id="sortOrder" name="sortOrder"
                           onblur="replaceSpace(this.value,this.id)" oninput="mobReg(this)">
                </div>
            </div>
            <div class="row cl col-sm-6">
                <label class="form-label col-xs-6 col-sm-4"><span class="c-red">*</span>头像：</label>

                <div class="formControls col-xs-8 col-sm-8">
                    <div class="imageShow imageAppend hide">
                        <ul class="clearfix fileCon">
                            <!--<li class='fl pos_r'><i class='pos_a iminus' onclick='isComfirm(this, 1, true)'></i><img  class="imgCon_01" src='${faceDetectFileInfo.ocrFrontFilePath}' onclick='imgClick(this)'/><span class='dis_b'></span></li>-->
                        </ul>
                    </div>
                    <div class="fileLoad pos_r addFileLoad">
                        <div class="btn btn-primary radius" onclick="fileClick()">选择图片</div>
                        <input type="file" class="pos_a hide" onchange="changeFile(this)">
                    </div>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-xs-12">
                <label class="form-label col-xs-6 col-sm-4" style="width: 118px;"><span class="c-red">*</span>产品详情：</label>
                <div class="formControls col-xs-8 col-sm-8">
                    <textarea type="text" name="detail" id="detail" style="width: 100%;height: 450px;"></textarea>
                </div>
            </div>
        </div>
        <div class="row cl marginTB">
            <div class="row cl col-sm-8">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-9">
                    <div class="btn btn-success radius" onclick="submit()">保存</div>
                </div>
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/js/H-ui.js"></script>
<script type="text/javascript" src="/js/H-ui.min.js"></script>
<script type="text/javascript" src="/js/postJson.js"></script>
<script type="text/javascript" src="/js/root.js"></script>
<script>

    /*提交*/
    var flag = true;
    var fileArr = [];
    function submit() {
        if (!flag) {
            return false;
        }
        flag = false;

        var name = $("#name").val();
        // var detail = $("#detail").val();
        var detail = UE.getEditor('detail').getContent();
        var unit = $("#unit").val();
        var custVipType = $("#custVipType").find("option:selected").val();
        var category = $("#category").find("option:selected").val();
        var vendor = $("#vendor").val();
        var price = $("#price").val();
        var cloudTicket = $("#cloudTicket").val();
        var cloudPoint = $("#cloudPoint").val();
        var thumbImagePath = $("#thumbImagePath").val();
        var sortOrder = $("#sortOrder").val();

        // var status = $("#status").val();


        if(name == '' || name == null) {
            parent.layer.msg('产品名称不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(detail == '' || detail == null) {
            parent.layer.msg('产品详情不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(unit == '' || unit == null) {
            parent.layer.msg('单位规格不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(custVipType == null || custVipType == '') {
            parent.layer.msg('客户类型不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(category == null || category == '') {
            parent.layer.msg('产品分类不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(vendor == null || vendor == '') {
            parent.layer.msg('产品供货商不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(price == null || price == '') {
            parent.layer.msg('产品单价不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }

        if(cloudTicket == null || cloudTicket == '') {
            parent.layer.msg('产品配送费不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }

        if(cloudPoint == null || cloudPoint == '') {
            parent.layer.msg('产品云积分不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }
        if(fileArr.length == 0) {
            parent.layer.msg('产品头像不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }

        if(sortOrder == null || cloudPoint == '') {
            parent.layer.msg('产品排序规则不能为空', {icon: 2, time: 3000});
            flag = true;
            return false;
        }

        var formData = new FormData();
        formData.append("name",name);
        formData.append("detail",detail);
        formData.append("unit",unit);
        formData.append("custVipType",custVipType);
        formData.append("category",category);
        formData.append("vendor",vendor);
        formData.append("price",price);
        formData.append("cloudPoint",cloudPoint);
        formData.append("cloudTicket",cloudTicket);
        formData.append("sortOrder",sortOrder);
        for(var i = 0; i < fileArr.length; i++){
            formData.append("thumbImagePath", fileArr[i]);
        }
        var url = "/productController/saveProduct";
        $.ajax({
            type: "post",
            url: url,
            data: formData,
            async: true,
            cache: false,
            contentType: false,
            processData: false,
            success: function (msg) {
                if (msg.success) {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.msg("操作成功！", {icon: 1, time: 3000});
                    parent.layer.close(index);
                } else {
                    parent.layer.msg(msg.errorMessage, {icon: 2, time: 5000});
                    flag = true;
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                var XmlStatus = XMLHttpRequest.status
                if (XmlStatus == 401) {
                    alert(XmlError.error401)
                    parent.window.location.href = "login"
                }
                if (XmlStatus == 403) {
                    alert(XmlError.error403)
                }
            }
        })
    }
    function changeFile(formDataArr) {
        var value = $(formDataArr).val();
        if(value == "") {
            return false;
        }
        var val = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
        if(val !== "png" && val !== "jpg" && val !== "jpeg" && val !== "bmp") {
            parent.layer.msg('图片格式不正确，请重新上传！', {icon: 2, time: 3000});
            return false;
        }
        fileArr.push(formDataArr.files[0]);
        forImage(formDataArr);
    }

    function fileClick(obj) {
        $("input[type=file]").click();
    }
    function forImage(data) {
        for(var i = 0; i < data.files.length; i++) {
            var file = new FileReader();
            file.readAsDataURL(data.files[i]);
            file.onload = function() {
                var img  = "<li class='fl pos_r imgCon'><i class='pos_a iminus' onclick='removeImg(this)'></i><img src='"+this.result+"' onclick='imgClick(this)'/></li>"
                $(".imageAppend").removeClass("hide").find("ul").append(img);
                $(".addFileLoad").addClass("hide");
            }
        }
    }
    //点击小图显示大图
    function imgClick(obj) {
        var src = $(obj).prop("src");
        window.open(src);
    }
    //删除图片
    function removeImg(obj) {
        $(".addFileLoad input").val("");
        fileArr = [];
        $(obj).parent().remove();
        $(".imageAppend").addClass("hide");
        $(".addFileLoad").removeClass("hide");
    }
   var ue = UE.getEditor('detail',{

    })
</script>
</body>
</html>